/**
 * 资源信息新增页面JS
 * User: zhaoming
 * Date: 15-8-17
 * Time: 下午5:58
 * To change this template use File | Settings | File Templates.
 */
$(function(){
    //激活左侧导航菜单
    activeNavBar("AUTHORITY_RESOURCE_INFO", "AUTHORITY");

    $("#resourceType").change(function(){
        $('#addForm').validator("cleanUp");
        var val = $(this).val();
        if(val == 1){
            $("#resourceIconDiv").show();
            $("#resourceUrlDiv").hide();

            $("#resourceUrl").val("");
            $("#resourceUrl").attr("disabled", true);
        }
        if(val == 2){
            $("#resourceIconDiv").show();
            $("#resourceUrlDiv").show();

            $("#resourceUrl").attr("disabled", false);
        }
        if(val == ""){
            $("#resourceIconDiv").hide();
            $("#resourceUrlDiv").hide();
        }
    });

    $("#save").click(function(){
        save();
    });

    $("#goBack").click(function(){
        window.history.back();
    });
});

/**
 * 保存
 */
function save(){
    if($('#addForm').trigger("validate").isValid()){
        Loading.show();
        jQuery.ajax({
            type: "POST",
            dataType: "json",
            url: springUrl+"/web/resourceInfo/insert",
            data: {
                parentResourceCode: $('#parentResourceCode').val(),
                resourceCode: $('#resourceCode').val(),
                resourceName: $('#resourceName').val(),
                resourceType: $('#resourceType').val(),
                resourceUrl: $('#resourceUrl').val(),
                resourceIcon: $('#resourceIcon').val() != "" ? $('#resourceIcon').val() : "leaf",
                resourceSort: $('#resourceSort').val(),
                remark: $('#remark').val()
            },
            success: function(data) {
                Loading.hide();
                Commons.showSuccess("数据保存成功!", function(){
                    window.location.href = "/web/resourceInfo/index";
                });
            },
            error: function(data){
                Loading.hide();
                Commons.showError("数据保存失败!");
            }
        });
    }

}

